<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分步表单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../js/lay-module/step-lay/step.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">产品类别</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="ptype" id="ptype"  placeholder="请填写商品类别" class="layui-input"  lay-verify="required" required/>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">产品名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="pname" id="pname" placeholder="请填写商品名称" class="layui-input"  lay-verify="required" required>
                                        </div>
                                    </div>
									<div class="layui-form-item">
									    <label class="layui-form-label">零售价</label>
									    <div class="layui-input-block">
									        <input type="text" name="price" id="price" placeholder="请填写零售价" class="layui-input" lay-verify="number" required>
									    </div>
									</div>
									<div class="layui-form-item">
									    <label class="layui-form-label">保质期</label>
									    <div class="layui-input-block">
									        <input type="text" name="validity" id="validity" placeholder="请填写保质期 /月"  class="layui-input" lay-verify="number" required>
									    </div>
									</div>                                                                   
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">原产地</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="production" name="production" placeholder="请输入原产地" value="" class="layui-input" lay-verify="required" required>
                                        </div>
                                    </div> 
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">生产时间</label>
                                        <div class="layui-input-block">
                                            <input id="picking" name="pcking" placeholder="请选择生产时间" value="" class="layui-input" lay-verify="required" required>
                                        </div>
                                    </div> 
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">发货时间</label>
                                        <div class="layui-input-block">
                                            <input id="shipping" name="shipping" placeholder="请选择发货时间" value="" class="layui-input" lay-verify="required"  required/>
                                        </div>
                                    </div> 
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">目的地</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="destination" id="destination" placeholder="请填写目的地" value="" class="layui-input"  lay-verify="required" required>
                                        </div>
                                    </div> 
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">收货时间</label>
                                        <div class="layui-input-block">
                                            <input  id="receiving" name="receiving" placeholder="请选择收获时间" value="" class="layui-input" lay-verify="required" required>
                                        </div>
                                    </div>                                   
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2" id="submit">
                                                &emsp;确认录入&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">										
										<h4 id="returnID"></h4>
                                        录入成功
                                    </div>
                                    <div style="font-size: 14px;color: #666;margin-top: 20px;"></div>
                                </div>
                                <div style="text-align: center;margin-top: 50px;">									
                                    <button class="layui-btn" id="reset">再次录入</button>
									<button class="layui-btn" id="show">查看信息</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div style="color: #666;margin-top: 30px;margin-bottom: 40px;padding-left: 30px;">
                        <h3>说明</h3><br>
                        
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use([ 'form', 'step','laydate','layer'], function () {
        var $ = layui.$,
            form = layui.form,
            step = layui.step,
			layer = layui.layer,
			laydate = layui.laydate;

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '产品信息'
            }, {
                title: '时效信息'
            }, {
                title: '完成'
            }]
        });
		
		//日期时间选择器
		  laydate.render({
		    elem: '#picking'
		    ,type: 'datetime'
		  });
		  laydate.render({
		    elem: '#shipping'
		    ,type: 'datetime'
		  });
		  laydate.render({
		    elem: '#receiving'
		    ,type: 'datetime'
		  });



        form.on('submit(formStep)', function () {
            step.next('#stepForm');
            return false;
        });
		var uid = $('#uid',parent.document).text();
        form.on('submit(formStep2)', function () {
			var product = {
				uid : uid,
				pid : 0,
				ptype : $("#ptype").val(),
				pname : $("#pname").val(),
				production : $("#production").val(),
				destination : $("#destination").val(),
				shipping : $("#shipping").val(),
				receiving: $("#receiving").val(),
				picking : $("#picking").val(),
				validity: $("#validity").val(),
				price: $("#price").val(),
				isback: 0
			};
			$.ajax({
				url: "http://localhost:9906/product/add",
				type: 'post',
				data: JSON.stringify(product),
				contentType: "application/json",
				success:function(response){
					console.log(response);
					if(response.code==200){
						step.next('#stepForm');						
						$("#returnID").text(response.msg);
					}else{
						layer.alert("添加失败，请检查数据！");
					}
				},
				error:function(){
					layer.alert("交互出现错误！请联系管理员！");
				}			
			});				
            return false;
        });
		
		
		$("#show").click(function(){
			var pid = $("#returnID").text();
			var index = layer.open({
			    title: '编辑用户',
			    type: 2,
			    shade: 0.2,
			    maxmin:true,
			    shadeClose: true,
			    area: ['80%', '100%'],
			    content: './edit.html?pid='+ pid,
			});
			$(window).on("resize", function () {
			    layer.full(index);
			});
			return false;
			
		});

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });
		
		$("#reset").click(function(){
			location.reload();
		});		
		
    })
</script>
</body>
</html>